#include"../h/queue_def.h"

/***********************************************************************
 * FUNCTION NAME: 
 *  tp_create_tasklist_queues_func
 * DESCRIPTION:
 *
 * INPUT: 
 *	request_msg_t *req_msg
 * OUTPUT:
 *	
 * RETURN:
 *	val_result
 * GLOBAL DATA REFERRED:
 *
 * CALLED ROUTINES:
 *
 * NOTES:
 *
 ************************************************************************/
U8 tp_create_tasklist_queues_func()
{
	U8 val_result = SYSLOG_TRUE;
	U32 msgid;
	val_result = msgget((key_t)TASKLIST_MQUEUE, 0666 | IPC_CREAT);
	if( SYSLOG_FAILURE == val_result){
		SYSLOG_TRANSPORT_ERROR_LOGGING("msgget failure with error: %d",errno);
		exit(EXIT_FAILURE);
	}
	return val_result;
}

/***********************************************************************
 * FUNCTION NAME: 
 *  send_request_to_tasklist_queues_func
 * DESCRIPTION: Send request to tasklist queues.
 *
 * INPUT: 
 *	request_msg_t *req_msg
 * OUTPUT:
 *	
 * RETURN:
 *	val_result
 * GLOBAL DATA REFERRED:
 *
 * CALLED ROUTINES:
 *
 * NOTES:
 *
 ************************************************************************/
U8 tp_send_request_to_tasklist_queues_func(struct request_msg_t *req_msg)
{
	U8 val_result = SYSLOG_TRUE;
	U32 msgid;
	msgid = msgget((key_t)TASKLIST_MQUEUE, 0666 | IPC_CREAT);
	if( SYSLOG_FAILURE == msgid){
		SYSLOG_TRANSPORT_ERROR_LOGGING("msgget failure with error: %d",errno);
		exit(EXIT_FAILURE);
	}
	
	if(SYSLOG_FAILURE == msgsnd(msgid,(void*)req_msg,MAX_TEXT,0) ){
		SYSLOG_TRANSPORT_ERROR_LOGGING("msgsnd failure with error: %d",errno);
		exit(EXIT_FAILURE);
	}

	return val_result;
}

/***********************************************************************
 * FUNCTION NAME: 
 *  receive_request_to_tasklist_queues_func
 * DESCRIPTION: Send request to tasklist queues.
 *
 * INPUT: 
 *	request_msg_t *req_msg
 * OUTPUT:
 *	
 * RETURN:
 *	val_result
 * GLOBAL DATA REFERRED:
 *
 * CALLED ROUTINES:
 *
 * NOTES:
 *
 ************************************************************************/
void* tp_receive_request_from_tasklist_queues_func(struct request_msg_t *req_msg)
{
	U8 val_result = SYSLOG_TRUE;
	U32 msgid;
	U32 msg_to_receive;
	msgid = msgget((key_t)TASKLIST_MQUEUE, 0666 | IPC_CREAT);
	if( SYSLOG_FAILURE == msgid)
	{
		SYSLOG_TRANSPORT_ERROR_LOGGING("msgget failure with error: %d",errno);
		return SYSLOG_NULL;
	}
	
	if(SYSLOG_FAILURE == msgrcv(msgid,(void*)req_msg,MAX_TEXT,msg_to_receive,0) ){
		SYSLOG_TRANSPORT_ERROR_LOGGING("msgrcv failure with error: %d",errno);
		return SYSLOG_NULL;
	}
	return req_msg;
}

/***********************************************************************
 * FUNCTION NAME: 
 *  create_input_queues_func
 * DESCRIPTION: Send request to tasklist queues.
 *
 * INPUT: 
 *	request_msg_t *req_msg
 * OUTPUT:
 *	
 * RETURN:
 *	val_result
 * GLOBAL DATA REFERRED:
 *
 * CALLED ROUTINES:
 *
 * NOTES:
 *
 ************************************************************************/
U8 create_input_queues_func()
{	return 0;}
/***********************************************************************
 * FUNCTION NAME: 
 *  send_request_to_input_queues_func
 * DESCRIPTION: Send request to tasklist queues.
 *
 * INPUT: 
 *	request_msg_t *req_msg
 * OUTPUT:
 *	
 * RETURN:
 *	val_result
 * GLOBAL DATA REFERRED:
 *
 * CALLED ROUTINES:
 *
 * NOTES:
 *
 ************************************************************************/
U8 send_request_to_input_queues_func()
{	return 0;}
/***********************************************************************
 * FUNCTION NAME: 
 *  receive_request_to_input_queues_func
 * DESCRIPTION: Send request to tasklist queues.
 *
 * INPUT: 
 *	request_msg_t *req_msg
 * OUTPUT:
 *	
 * RETURN:
 *	val_result
 * GLOBAL DATA REFERRED:
 *
 * CALLED ROUTINES:
 *
 * NOTES:
 *
 ************************************************************************/
U8 receive_request_to_input_queues_func()
{	return 0;}
/***********************************************************************
 * FUNCTION NAME: 
 *  monitor_tasklist_queues_func
 * DESCRIPTION:
 *
 * INPUT: 
 *	request_msg_t *req_msg
 * OUTPUT:
 *	
 * RETURN:
 *	val_result
 * GLOBAL DATA REFERRED:
 *
 * CALLED ROUTINES:
 *
 * NOTES:
 *
 ************************************************************************/
U8 tp_monitor_tasklist_queues_func()
{
	U8 val_result = SYSLOG_TRUE;
	U32 msgid;
	U32 msg_to_receive;
	struct request_msg_t *req_msg;
	msgid = msgget((key_t)TASKLIST_MQUEUE, 0666 | IPC_CREAT);
	if( SYSLOG_FAILURE == msgid)
	{
		SYSLOG_TRANSPORT_ERROR_LOGGING("msgget failure with error: %d",errno);
		return SYSLOG_NULL;
	}

	while(1)
	{
		if(SYSLOG_FAILURE == msgrcv(msgid,(void*)req_msg,MAX_TEXT,msg_to_receive,0) ){
			SYSLOG_TRANSPORT_ERROR_LOGGING("msgrcv failure with error: %d",errno);
			return SYSLOG_NULL;
		}
		else
		{
			/*Handle Request*/
			switch(req_msg->action)
			{
			case CREATE_CONNECTION:
				break;
			case REMOVE_CONNECTION:
				break;
			default:
				break;
			}
			/*memset req_msg*/

		}

	}
	return 0;
}
/***********************************************************************
 * FUNCTION NAME: 
 *  monitor_input_queues_func
 * DESCRIPTION: Send request to tasklist queues.
 *
 * INPUT: 
 *	request_msg_t *req_msg
 * OUTPUT:
 *	
 * RETURN:
 *	val_result
 * GLOBAL DATA REFERRED:
 *
 * CALLED ROUTINES:
 *
 * NOTES:
 *
 ************************************************************************/
U8 monitor_input_queues_func()
{	return 0;}
